<?php 
	require $_SERVER['DOCUMENT_ROOT'] . '/deviantpic/inc/doctype.php'; 
	require $_SERVER['DOCUMENT_ROOT'] . '/deviantpic/inc/database.php';
	
	//Get photos
	$photos = array();
	$query = "SELECT photos.id AS id, photos.photo AS photo, photos.title AS title, photos.time_uploaded AS time FROM photos ORDER BY time DESC";
	$result = mysql_query($query) or die(mysql_error());
			
	$index = 0;
	$index_max = mysql_num_rows($result);
	
	if ($index_max>10) $index_max=10;
	
	while($index<$index_max) {
		$row = mysql_fetch_array($result);
		$photos[] = $row;
		$index++;
	}
?>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>deviantPIC</title>
    </head>
    <body>
		<!-- Header -->
		<?php require $_SERVER['DOCUMENT_ROOT'] . '/deviantpic/inc/header.php'; ?>

		<!-- Content -->
		<div id="body">
			<h2>Latest pictures</h2>

			<!-- Pictures -->
			<div class="pictures" id="latest-pictures">
				<?php 
					foreach ($photos as $photo) {
						echo ' <span class="photo-thumbnail">
							<a href="/deviantpic/picture/view.php?id='.$photo['id'].'">
								<img src="' . $photo['photo'] . '" alt= ' . $photo['title'] . ' width="100" height="100"/>
							</a>
						</span>
						';
					}
				?>
			</div>
		</div>

		<!-- Footer -->
		<?php require $_SERVER['DOCUMENT_ROOT'] . '/deviantpic/inc/footer.php'; ?>
    </body>
</html>
